unit untPesquisas;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxStyles, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCaramel,
  dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSharp, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxCheckBox, Menus, StdCtrls,
  cxButtons, ExtCtrls, ActnList, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  dxmdaset, ADODB, ShellApi, jpeg, ppCtrls, myChkBox, ppDB, ppVar,
  ppPrnabl, ppClass, ppBands, ppCache, ppParameter, ppDBPipe, ppComm,
  ppRelatv, ppProd, ppReport, cxTextEdit;

type
  TfrmPesquisas = class(TForm)
    QryPesquisas: TADOQuery;
    QryPesquisasCODIGO: TAutoIncField;
    QryPesquisasDESCRICAO: TWideStringField;
    QryPesquisasRET: TWideStringField;
    QryPesquisasENDERECO: TWideStringField;
    mtbPesquisa: TdxMemData;
    mtbPesquisaDESCRICAO: TStringField;
    mtbPesquisaENDERECO: TStringField;
    mtbPesquisaPESQUISAR: TBooleanField;
    TVPesquisa: TcxGridDBTableView;
    LVPesquisa: TcxGridLevel;
    Grid: TcxGrid;
    dsPesquisa: TDataSource;
    TVPesquisaRecId: TcxGridDBColumn;
    TVPesquisaDESCRICAO: TcxGridDBColumn;
    TVPesquisaENDERECO: TcxGridDBColumn;
    TVPesquisaPESQUISAR: TcxGridDBColumn;
    ActionList1: TActionList;
    ActSave: TAction;
    ActESC: TAction;
    ActSel: TAction;
    Panel1: TPanel;
    cxButton2: TcxButton;
    cxButton1: TcxButton;
    ActImprimir: TAction;
    rptPesquisas: TppReport;
    ppPesquisas: TppDBPipeline;
    ppParameterList1: TppParameterList;
    ppHeaderBand1: TppHeaderBand;
    ppDetailBand1: TppDetailBand;
    ppFooterBand1: TppFooterBand;
    ppShape1: TppShape;
    ppSystemVariable1: TppSystemVariable;
    ppLabel1: TppLabel;
    mtbPesquisaCLIENTE: TStringField;
    ppDBText1: TppDBText;
    ppLabel3: TppLabel;
    ppShape2: TppShape;
    ppLabel4: TppLabel;
    ppLabel5: TppLabel;
    ppShape3: TppShape;
    ppDBText2: TppDBText;
    ppShape4: TppShape;
    ppShape5: TppShape;
    myDBCheckBox1: TmyDBCheckBox;
    ppImage1: TppImage;
    ppShape6: TppShape;
    PopupMenu1: TPopupMenu;
    MarcarTodos1: TMenuItem;
    DesmarcarTodos1: TMenuItem;
    N1: TMenuItem;
    PesquisarIten1: TMenuItem;
    procedure FormShow(Sender: TObject);
    procedure ActSaveExecute(Sender: TObject);
    procedure ActESCExecute(Sender: TObject);
    procedure ActSelExecute(Sender: TObject);
    procedure MarcarTodos1Click(Sender: TObject);
    procedure DesmarcarTodos1Click(Sender: TObject);
    procedure PesquisarIten1Click(Sender: TObject);
  private
    { Private declarations }
    procedure Selecionar(Sel:Boolean);
  public
    cliente : string;
    { Public declarations }
  end;

var
  frmPesquisas: TfrmPesquisas;

implementation

uses untPrincipal;

{$R *.dfm}

procedure TfrmPesquisas.FormShow(Sender: TObject);
begin
  QryPesquisas.Close;
  QryPesquisas.Open;
  QryPesquisas.First;
  mtbPesquisa.Open;
  while not QryPesquisas.Eof do
  begin
    mtbPesquisa.Append;
    mtbPesquisaDESCRICAO.Value := QryPesquisasDESCRICAO.Value;
    mtbPesquisaCLIENTE.Value := cliente;
    mtbPesquisaENDERECO.Value := QryPesquisasENDERECO.Value;
    mtbPesquisaPESQUISAR.Value := True;
    mtbPesquisa.Post;

    QryPesquisas.Next;
  end;
  mtbPesquisa.First;

end;

procedure TfrmPesquisas.ActSaveExecute(Sender: TObject);
begin
  mtbPesquisa.First;
  while not mtbPesquisa.Eof do
  begin
    if mtbPesquisaPESQUISAR.Value then
       ShellExecute(Handle, 'open',Pchar(mtbPesquisaENDERECO.Text), '', '', 1);
    mtbPesquisa.Next;
  end;
  rptPesquisas.Print;
end;

procedure TfrmPesquisas.ActESCExecute(Sender: TObject);
begin
  close;
end;

procedure TfrmPesquisas.ActSelExecute(Sender: TObject);
begin
  mtbPesquisa.Edit;
  mtbPesquisaPESQUISAR.Value := not(mtbPesquisaPESQUISAR.Value);
end;

procedure TfrmPesquisas.MarcarTodos1Click(Sender: TObject);
begin
  Selecionar(True);
end;

procedure TfrmPesquisas.Selecionar(Sel: Boolean);
var
  book : TBookmark;
begin
  book := mtbPesquisa.GetBookmark;
  mtbPesquisa.DisableControls;
  mtbPesquisa.First;
  while not mtbPesquisa.Eof do
  begin
    mtbPesquisa.Edit;
    mtbPesquisaPESQUISAR.Value := Sel;
    mtbPesquisa.Post;
    mtbPesquisa.Next;
  end;
  mtbPesquisa.GotoBookmark(book);
  mtbPesquisa.EnableControls;
  mtbPesquisa.FreeBookmark(book);
end;

procedure TfrmPesquisas.DesmarcarTodos1Click(Sender: TObject);
begin
  Selecionar(False);
end;

procedure TfrmPesquisas.PesquisarIten1Click(Sender: TObject);
begin
  ShellExecute(Handle, 'open',Pchar(mtbPesquisaENDERECO.Text), '', '', 1);
end;

end.
